package com.kun.service_order.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kun.service_order.entity.TOrder;
import com.kun.service_order.service.TOrderService;
import com.kun.utils.JwtUtils;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author dmk
 * @since 2021-10-31
 */
@RestController
@CrossOrigin
@RequestMapping("/service_order/t-order")
public class TOrderController {
    @Autowired
    private TOrderService orderService;
    @PostMapping("createOrder/{courseId}")
    public R saveOrder(@PathVariable String courseId, HttpServletRequest request){

        String orderNo= orderService.createOrders(courseId,JwtUtils.getMemberIdByJwtToken(request));
        return R.ok().data("orderNo",orderNo);
    }

    @GetMapping("getOrderInfo/{orderId}")
    public R getOrderInfo(@PathVariable String orderId){
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderId);
        TOrder order = orderService.getOne(wrapper);
        return R.ok().data("order",order);
    }

}

